package com.supermap.dialogs;

import com.supermap.Helper;
import com.supermap.dialogs.advance.CJDialog;

import javax.swing.*;
import java.awt.*;

public class DatasetGridAddToSceneDialog extends CJDialog {
    private JCheckBox addToTerrainLayersCbx;
    private JCheckBox addToSceneLayersCbx;

    private boolean isAddToTerrainLayers;
    private boolean isAddToSceneLayers;
    private String datasetName;

    public DatasetGridAddToSceneDialog(Frame owner, String title, boolean modal, String datasetName) {
        super(owner, title, modal, 250, 120, new Object[]{datasetName});
    }

    @Override
    protected void initializeArgs(Object[] args) {
        isAddToTerrainLayers = true;
        isAddToSceneLayers = false;
        datasetName = (String) args[0];
    }

    @Override
    protected void initializeCore() {
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new GridBagLayout());
        add(centerPanel, BorderLayout.CENTER);

        addToTerrainLayersCbx = new JCheckBox("将数据集\"" + datasetName + "\"作为地形加载");
        centerPanel.add(addToTerrainLayersCbx, new GridBagConstraints(0, 0, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, Helper.DefaultInsets, 0, 0));
        addToTerrainLayersCbx.setSelected(isAddToTerrainLayers);
        addToTerrainLayersCbx.addActionListener(e -> {
            isAddToTerrainLayers = addToTerrainLayersCbx.isSelected();
            super.confirmBtn.setEnabled(isAddToSceneLayers || isAddToTerrainLayers);
        });

        addToSceneLayersCbx = new JCheckBox("将数据集\"" + datasetName + "\"作为影像加载");
        centerPanel.add(addToSceneLayersCbx, new GridBagConstraints(0, 1, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, Helper.DefaultInsets, 0, 0));
        addToSceneLayersCbx.setSelected(isAddToSceneLayers);
        addToSceneLayersCbx.addActionListener(e -> {
            isAddToSceneLayers = addToSceneLayersCbx.isSelected();
            super.confirmBtn.setEnabled(isAddToSceneLayers || isAddToTerrainLayers);
        });
    }

    @Override
    protected void doConfirmCore() {
        setVisible(false);
    }

    public boolean isAddToTerrainLayers() {
        return isAddToTerrainLayers;
    }

    public boolean isAddToSceneLayers() {
        return isAddToSceneLayers;
    }
}
